package spit;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;

import javax.swing.JPanel;

public class InterRoundPanel extends JPanel {
	
	final private String winRound = "You've won the round! Choose a pile...";
	final private String loseRound = "You've lost! Computer gets to choose a deck.";
	
	String message;
	String status;
	
	Point spitPileOneLocation;
	Point spitPileTwoLocation;
	Point spitPileThreeLocation;
	
	boolean won;
	
	int spitPileOneCards;
	int spitPileTwoCards;
	int spitPileThreeCards;
	
	InterRoundPanel(Point firstLocation, Point secondLocation, Point thirdLocation )
	{
		message = "";
		
		spitPileOneCards = 0;
		spitPileTwoCards = 0;
						
		spitPileOneLocation = firstLocation;
		spitPileTwoLocation = secondLocation;
		spitPileThreeLocation = thirdLocation;
	}
	
    // This is Swing, so override paint*Component* - not paint
    protected void paintComponent(Graphics g) {
        // call super.paintComponent to get default Swing 
        // painting behavior (opaque honored, etc.)
        super.paintComponent(g);
        int x = 0;
        int y = 0;
        int width = getWidth();
        int height = getHeight();
        
        Graphics2D g2d = (Graphics2D) g;
        
        drawBlack(g2d);
        
        drawMessage(g2d);
        
        drawCardCount(g2d);
        
        
            
    }
    
    public void drawBlack(Graphics2D g2d)
    {
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.6f));
        g2d.setColor(Color.BLACK);
        g2d.fillRect(0, 0, getWidth(), getHeight());
    }
    
    public void drawMessage(Graphics2D g2d)
    {

            g2d.setComposite(AlphaComposite.getInstance(
                    AlphaComposite.SRC_OVER, 0.7f));
            g2d.setColor(Color.YELLOW);
            g2d.setFont(new Font("Serif", Font.BOLD, 40));
            g2d.drawString(message, spitPileOneLocation.x-170, spitPileOneLocation.y - 10);

        
    }
    
    public void drawCardCount(Graphics2D g2d)
    {
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.7f));
        g2d.setColor(Color.YELLOW);
        g2d.setFont(new Font("Serif", Font.BOLD, 40));
        if (spitPileOneCards > 0 )
        {
        	g2d.drawString(String.valueOf(spitPileOneCards), spitPileOneLocation.x + 30, spitPileOneLocation.y + 70);
        }
        else
        {
        	g2d.drawString("", spitPileOneLocation.x + 30, spitPileOneLocation.y + 70);
        }
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.7f));
        g2d.setColor(Color.YELLOW);
        g2d.setFont(new Font("Serif", Font.BOLD, 40));
        if ( spitPileTwoCards > 0)
        {
        	g2d.drawString(String.valueOf(spitPileTwoCards), spitPileTwoLocation.x + 30, spitPileTwoLocation.y + 70);
        }
        else
        {
        	g2d.drawString("", spitPileOneLocation.x + 30, spitPileOneLocation.y + 70);
        }
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.7f));
        g2d.setColor(Color.YELLOW);
        g2d.setFont(new Font("Serif", Font.BOLD, 40));
        if ( spitPileThreeCards > 0 )
        {
        	g2d.drawString(String.valueOf(spitPileThreeCards), spitPileThreeLocation.x + 30, spitPileThreeLocation.y + 70);
        }
        else
        {
        	g2d.drawString("", spitPileOneLocation.x + 30, spitPileOneLocation.y + 70);
        }
        
    }

    public void setSpitPileOneCards(int count)
    {
    	spitPileOneCards = count;
    }
    
    public void setSpitPileTwoCards ( int count )
    {
    	spitPileTwoCards = count;
    }
    
    public void setSpitPileThreeCards ( int count )
    {
    	spitPileThreeCards = count;
    }
    
    public void signalPlayerWinIs(boolean winStatus)
    {
    	won = winStatus;
    	if (won)
    	{
    		message = winRound;
    	}
    	else
    	{
    		message = loseRound;
    	}
    	System.out.println(message);
    }
}
